<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="房屋编号" prop="houseId">
        <el-input
          v-model="queryParams.houseId"
          placeholder="请输入房屋编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="refundDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.refundDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择退款开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="refundDate1">
          <el-date-picker clearable size="small"
            v-model="queryParams.refundDate1"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择退款结束时间">
          </el-date-picker>
        </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="refundQueryList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="小区" align="center" prop="areaName" />
      <el-table-column label="楼宇" align="center" prop="groupName" />
      <el-table-column label="单元" align="center" prop="unitName" />
      <el-table-column label="户" align="center" prop="doorName" />
      <el-table-column label="房屋编号" align="center" prop="houseId" />
      <el-table-column label="退款金额" align="center" prop="refundMoney" />
      <el-table-column label="退款时间" align="center" prop="refundDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.refundDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收费员" align="center" prop="creater" />
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listRefundQuery, getRefundQuery, delRefundQuery, addRefundQuery, updateRefundQuery } from "@/api/fund/refundQuery";
import {getNote} from "../../../api/fund/refundQuery";
export default {
  name: "RefundQuery",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 退款查询表格数据
      refundQueryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        houseId: null,
        refundDate: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    onPrint(row) {
      this.reset();
      debugger
      const costId = row.costId || this.ids
      getNote(costId).then(response=>{
        debugger
        const printNode = this.$refs.print
        if(!printNode) return
        const newIframe = document.createElement('iframe');
        newIframe.setAttribute('style', 'width:0px;height:0px;position:absolute;left:-9999px;top:-9999px;');
        newIframe.setAttribute('align', 'center');
        document.body.appendChild(newIframe);
        document.getElementById("refundMoney").innerHTML=response.data.refundMoney;
        document.getElementById("refundDate").innerHTML=response.data.refundDate;
        document.getElementById("creater").innerHTML=response.data.creater;
        document.getElementById("areaName").innerHTML=response.data.areaName;
        document.getElementById("groupName").innerHTML=response.data.groupName;
        document.getElementById("unitName").innerHTML=response.data.unitName;
        document.getElementById("doorName").innerHTML=response.data.doorName;
        document.getElementById("unit").innerHTML="房产管理局物业管理办公室";
        let doc = null;
        doc = newIframe.contentWindow.document;
        doc.write(`
            <style type="text/css">
              @media print {
                @page {
                  size: auto;
                  margin: 1mm;
                  table { page-break-after: auto; }
                  tr    { page-break-inside: avoid; page-break-after: auto; }
                  td    { page-break-inside: avoid; page-break-after: auto; }
                  thead { display: table-header-group; }
                  tfoot { display: table-footer-group; }
                }
              }
              .print-preview { display: flex; flex-direction: column; color: rgba(51, 51, 51, 1); font-family: Microsoft YaHei, '黑体', STSong, '宋体',Consolas, Monaco, Droid, Sans, Mono, Source, Code, Pro, Menlo, Lucida, Sans, Type, Writer, Ubuntu, Mono; }
              .title { display: flex; justify-content: center; font-size: 21px; height: 50px; line-height: 50px; font-weight: bold; }
              .divide_line { justify-content: center; border-bottom: 1px dashed rgba(51, 51, 51, 1); }
              body{
                          margin:0;
                      }
                      .main {
                          width: 1470px;
              		    height: 622px;
              		    border: 0px #000 solid;
                          color: #000;
                          font-weight:bold;
                          line-height: 13px;
                          font-size: 28px;
                          position: relative;
                      }
                      .main div{
                          z-index: 11;
                          position: absolute;
                          /*background:#0f0;*/
                          height: 13px;
                      }
                            .img1{
                                width: 100%;
                                position: absolute;
                                top:0;
                                z-index: 1;
                                display: none;
                            }
                            .div2{
                                top: 83px;
                                left: 300px;
                                width: 100px;
                            }
                            .div3{
                                top: 83px;
                                left: 390px;
                                width: 100px;
                            }

                            .div5{
                                top: 140px;
                                left: 300px;
                                width: 300px;
                            }
                            .div6{
                                top: 140px;
                                left: 855px;
                                width: 400px;
                            }
                            .div8{
                                top: 224px;
                                left: 885px;
                                width: 300px;
                            }

                            .div10{
                                top: 300px;
                                left: 300px;
                                width: 600px;
                            }
                        .div11{
                                top: 440px;
                                left: 300px;
                                width: 330px;
                            }
                        .div12{
                          top: 447px;
                          left: 920px;
                          width: 300px;
                        }
                        .div13{
                          top: 500px;
                          left: 300px;
                          width: 300px;
                        }
                        .div14{
                          top: 500px;
                          left: 643px;
                          width: 300px;
                        }
                  </style>
            <div style="width:100%;height:auto;width:320px;margin:0px auto;"align="center">
              ${printNode.innerHTML}
            </div>`)
        doc.close();
        setTimeout(() => {
          newIframe.contentWindow.focus();
          newIframe.contentWindow.print();
          document.body.removeChild(newIframe);
        }, 10);
      })
    },
    /** 查询退款查询列表 */
    getList() {
      this.loading = true;
      listRefundQuery(this.queryParams).then(response => {
        this.refundQueryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        refundId: null,
        costId:null,
        houseId: null,
        refundMoney: null,
        refundDate: null,
        costMoney: null,
        creater: null,
        createDate: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      debugger
      this.ids = selection.map(item => item.costId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加退款查询";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const refundId = row.refundId || this.ids
      getRefundQuery(refundId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改退款查询";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.refundId != null) {
            updateRefundQuery(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRefundQuery(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const refundIds = row.refundId || this.ids;
      this.$modal.confirm('是否确认删除退款查询编号为"' + refundIds + '"的数据项？').then(function() {
        return delRefundQuery(refundIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('fund/refundQuery/export', {
        ...this.queryParams
      }, `refundQuery_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
